package com.ccjk.beusoft.thirdlib.plugin2.hook.proxy;

import android.content.pm.PackageInfo;
import android.text.TextUtils;

import com.ccjk.beusoft.thirdlib.plugin2.PluginManager2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by CCJK on 2017/12/22.
 */

public class PmsProxy implements InvocationHandler {
    private Object origin;

    public PmsProxy(Object origin) {
        this.origin = origin;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //插件的Application的创建过程中会去检查PackageInfo
        //  pi = pm.getPackageInfo(mPackageName, 0, UserHandle.myUserId());
        if (TextUtils.equals(method.getName(), "getPackageInfo")) {
            if (PluginManager2.get().isPlugin(args[0].toString())) {
                return new PackageInfo();
            }
        }
        return method.invoke(origin, args);
    }
}
